<?php
require_once(CONF_DIR . '/NicknameFilter.conf.php');

class NicknameFilter implements iFilter
{
	public static $filter_nicknames;
	
	public function __construct()
	{
		if(!self::$filter_nicknames)
		{
			$nickname_list = fopen(CONF_DIR . '/NicknameFilters.txt','r');
			
			while(!feof($nickname_list))
			{
				$nickname = trim(fgets($nickname_list));
				if($nickname)
				{
					self::$filter_nicknames[] = $nickname;
				}	
			}
			
			fclose($nickname_list);
		}
	}
	
	public function applyFilter($echo)
	{
		foreach(self::$filter_nicknames as $filter_nickname)
		{
			if($echo['nickname'] == $filter_nickname)
			{
				return false;	
			}
			if(FILTER_REPLYTO && $echo['replyto'] == ">>" . $filter_nickname)
			{
				return false;
			}
		} 	
		
		return $echo;
	}
}
?>